﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _23_FileStream
{
    class Program
    {
        static void Main(string[] args)
        {
            //FileStream 读取文件时一点一点的读，相对于File对内存压力较小
            //StreamReader StreamWriter
            string source = @"F:\BaiduYunDownload\018_设备树详解(29节，4节免费，已完结)\videos\第01课_设备树的引进与体验(6节，4节免费)\第01节_字符设备驱动程序的三种写法(免费).zip";
            string target = @"C:\Users\SRLS_Liu\Desktop\new.zip";
            CopyFile(source, target);
            Console.ReadKey();
        }

        static void CopyFile(string soure , string target)
        {
            using (FileStream fsRead = new FileStream(soure, FileMode.OpenOrCreate, FileAccess.Read))
            {
                byte[] buffer = new byte[1024 * 1024 * 5];
                using (FileStream fsWrite = new FileStream(target, FileMode.Create, FileAccess.Write))
                {
                    while (true)
                    {
                        int r = fsRead.Read(buffer, 0, buffer.Length);
                        fsWrite.Write(buffer, 0, r);
                        if (r == 0)
                        {
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("拷贝成功");
        }
    }
}
